package com.lwc.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Rabbitconfig {

    /**
     * 错误队列
     * @return
     */
    @Bean
    public Queue queueError(){
        return  new Queue("queue-error");
    }
    /**
     * 消息队列
     * @return
     */
    @Bean
    public  Queue queueMsg(){
        return  new Queue("queue-msg");
    }
    /**
     * 订单队列
     * @return
     */
    @Bean
    public  Queue queueOrder(){
        return  new Queue("order-queue");
    }

    /**
     * 话题交换器
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){
        return  new TopicExchange("log-ex");
    }

    //错误队列和交换器绑定
    @Bean
    public Binding bindingQueueError(TopicExchange topicExchange,Queue queueError){
        return BindingBuilder.bind(queueError).to(topicExchange).with("*.*.error");
    }


    //消息和交换器绑定
    @Bean
    public Binding bindingqueueMsg(TopicExchange topicExchange,Queue queueMsg){
        return BindingBuilder.bind(queueMsg).to(topicExchange).with("*.*.info");
    }
    //订单和交换器绑定
    @Bean
    public Binding bindingqueueOrder(TopicExchange topicExchange,Queue queueOrder){
        return BindingBuilder.bind(queueOrder).to(topicExchange).with("order.#");
    }

}
